/**
 *
 */
package com.csun.cmny.provider.utils;

import com.csun.cmny.provider.model.vo.DisinfectionVo;
import com.csun.cmny.provider.model.vo.NursinglogDetailVo;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liqian
 * @date   2018年4月10日
 * @time   下午3:20:36
 * Description : 护工护理日志工具类、菜单
 */
public class NursinglogUtil {

    //获取膳食集合
    public static List<NursinglogDetailVo> setMealList(String meal){
        //膳食服务集合
        List<NursinglogDetailVo> mealList = new ArrayList<NursinglogDetailVo>();
        //获取膳食数组
        String meals[] =meal.split("μ");
        for(int i=0;i<=meals.length-1;i++){
            //单个膳食记录
            NursinglogDetailVo nlogDetail = new NursinglogDetailVo();
            String str[] = meals[i].split("ν");
            //获取类型
            nlogDetail.setType(Integer.valueOf(str[0]));//类型 1 早餐 2 中餐 3 晚餐
            String oldMans[] = str[1].split("-");
            //老人id集合
            List<Integer> oldManList = new ArrayList<Integer>();
            //老人姓名集合
            List<String> oldmanNameList = new ArrayList<>();
            //获取老人id集合，默认插入的是0，如果是0则代表没有数据
            if (!(str[1].equals("0"))) {
                for (int k = 0; k <= oldMans.length - 1; k++) {
                    /*
                    * 2019-11-21
                    * 结构修改为:
                    * oldmans[k] : 老人id:老人姓名
                    * */
                    String[] oldmanIdAndOldmanName = oldMans[k].split(":");
                    Integer oldManId = Integer.valueOf(oldmanIdAndOldmanName[0]);
                    oldmanNameList.add(oldmanIdAndOldmanName[1]);
                    oldManList.add(oldManId);//添加到老人id集合
                }
            }
            //设置单个记录的老人Id集合
            nlogDetail.setOldMans(oldManList);
            nlogDetail.setOldManNameList(oldmanNameList);
            //获取特殊情况，默认插入的是0，如果是0则代表没有数据
            if (!(str[2].equals("0"))) {
                nlogDetail.setRemark(str[2]);
            }
            //添加到膳食服务集合
            mealList.add(nlogDetail);
        }
        return mealList;
    }
    //获取消毒集合
    public static List<NursinglogDetailVo> setDisinfectionList(String disinfection){
        //消毒集合
        List<NursinglogDetailVo> disinfectionList = new ArrayList<NursinglogDetailVo>();
        //获取消毒数组
        String disinfections[] =disinfection.split(";");
        for(int i=0;i<=disinfections.length-1;i++){
            String str[] = disinfections[i].split(",");
            //某个类型的消毒记录
            NursinglogDetailVo nlogDetail = new NursinglogDetailVo();
            //某个类型的消毒记录集合
            List<DisinfectionVo> disList = new ArrayList<DisinfectionVo>();
            for(int j=0;j<=str.length-1;j++){
                //消毒记录
                DisinfectionVo dis = new DisinfectionVo();
                //具体内容数组
                String arr[] = str[j].split("-");
                nlogDetail.setType(Integer.valueOf(arr[0]));//类型4-餐具，5-物品，6-地面，7-厕所，8-便器，9-其他
                dis.setWay(Integer.valueOf(arr[1]));//方法 1-洗抹 2-消毒柜 3-药水 4-紫外线
                dis.setReagent(Integer.valueOf(arr[2]));//试剂 1来苏儿 2-84消毒液 3-洁厕剂 4-洗涤剂
                dis.setTime(Integer.valueOf(arr[3]));//时间

                if (!arr[4].equals("0")) {
                    String[] userIdAndName = arr[4].split(":");
                    dis.setUserId(userIdAndName[0]);//负责人
                    dis.setUserName(userIdAndName[1]);
                }
//                dis.setUserId(arr[4]);//负责人
                //添加到某个类型的消毒记录集合
                disList.add(dis);
            }
            //设置某个类型的消毒记录集合
            nlogDetail.setDisList(disList);
            //添加到消毒集合
            disinfectionList.add(nlogDetail);
        }

       /* //消毒集合
        List<NursinglogDetailVo> disinfectionList = new ArrayList<NursinglogDetailVo>();
        //获取消毒数组
        String disinfections[] =disinfection.split(";");
        for(int i=0;i<=disinfections.length-1;i++){
            String str[] = disinfections[i].split(",");
            //某个类型的消毒记录
            NursinglogDetailVo nlogDetail = new NursinglogDetailVo();
            //某个类型的消毒记录集合
            List<DisinfectionVo> disList = new ArrayList<DisinfectionVo>();
            for(int j=0;j<=str.length-1;j++){
                //消毒记录
                DisinfectionVo dis = new DisinfectionVo();
                //具体内容数组
                String arr[] = str[j].split("-");
                nlogDetail.setType(Integer.valueOf(arr[0]));//类型4-餐具，5-物品，6-地面，7-厕所，8-便器，9-其他
                dis.setWay(Integer.valueOf(arr[1]));//方法 1-洗抹 2-消毒柜 3-药水 4-紫外线
                dis.setReagent(Integer.valueOf(arr[2]));//试剂 1来苏儿 2-84消毒液 3-洁厕剂 4-洗涤剂
                dis.setTime(Integer.valueOf(arr[3]));//时间

                *//*
                * 2019-11-21
                * 结构修改为:
                * oldmans[k] : 护工id:护工姓名
                * *//*
                if (!arr[4].equals("0")) {
                    String[] userIdAndName = arr[4].split(":");
                    dis.setUserId(userIdAndName[0]);//负责人
                    dis.setUserName(userIdAndName[1]);
                }

                //添加到某个类型的消毒记录集合
                disList.add(dis);
            }
            //设置某个类型的消毒记录集合
            nlogDetail.setDisList(disList);
            //添加到消毒集合
            disinfectionList.add(nlogDetail);
        }*/

        return disinfectionList;
    }

    // 从 list 转 string
    public static String getDisinfectionByList(List<NursinglogDetailVo> disinfectionList) {
        List<String> ndStrList = Lists.newArrayList();
        List<String> dfStrList = Lists.newArrayList();
        List<String> typeStrList = Lists.newArrayList();
        int type = 1;
        for (NursinglogDetailVo nd : disinfectionList) {
            if (type != nd.getType()) {
                typeStrList.add(StringUtils.join(ndStrList,","));
                ndStrList.clear();
                type = nd.getType();
            }
            for (DisinfectionVo df : nd.getDisList()) {
                dfStrList.add(nd.getType() + "");
                dfStrList.add(df.getWay() + "");
                dfStrList.add(df.getReagent() + "");
                dfStrList.add(df.getTime() + "");
                dfStrList.add(df.getUserId());

                ndStrList.add(StringUtils.join(dfStrList, "-"));
                dfStrList.clear();
            }
        }
        typeStrList.add(StringUtils.join(ndStrList,","));
        return StringUtils.join(typeStrList,";");
    }

    //获取其他集合
    public static List<NursinglogDetailVo> setInfoList(String info){
        //服务集合
        List<NursinglogDetailVo> infoList = new ArrayList<NursinglogDetailVo>();
        //获取服务数组
        String infos[] =info.split(";");
        for(int i=0;i<=infos.length-1;i++){
            //服务
            NursinglogDetailVo nlogDetail = new NursinglogDetailVo();
            String str[] = infos[i].split(",");
            //第二个存放的是负责人id
//            nlogDetail.setUserId(str[1]);
            /*
             * 2019-11-21
             * 结构修改为:
             * oldmans[k] : 护工id:护工姓名
             * */
            if(!infos[i].equals("0,0")){
                String[] userIdAndName = str[1].split(":");
                nlogDetail.setUserId(userIdAndName[0]);
                nlogDetail.setUserName(userIdAndName[1]);
            }else{
                nlogDetail.setUserId("0");
                nlogDetail.setUserName("0");
            }
            //获取老人数组
            String oldMans[] = str[0].split("-");
            //老人id集合
            List<Integer> oldManList = new ArrayList<Integer>();
            //老人姓名集合
            List<String> oldmanNameList = Lists.newArrayList();
            for(int j=0;j<=oldMans.length-1;j++){
                if (!oldMans[j].equals("0")) {
                    /*
                     * 2019-11-21
                     * 结构修改为:
                     * oldmans[k] : 老人id:老人姓名
                     * */
//                    oldmanList.add(Integer.valueOf(oldMans[k]));
                    String[] oldmansIdAndName = oldMans[j].split(":");
                    oldManList.add(Integer.parseInt(oldmansIdAndName[0]));
                    oldmanNameList.add(oldmansIdAndName[1]);
                }

            }
            nlogDetail.setOldMans(oldManList);
            nlogDetail.setOldManNameList(oldmanNameList);
            infoList.add(nlogDetail);
        }
        return infoList;
    }

    public static String getInfoByList(List<NursinglogDetailVo> nlogDetailList) {

        List<String> nldList = Lists.newArrayList();
        for (NursinglogDetailVo nd : nlogDetailList) {
            List<String> ndList = Lists.newArrayList();
            List<Integer> idList = Lists.newArrayList();
            for (int id : nd.getOldMans()) {
                idList.add(id);
            }
            String str = StringUtils.join(idList, "-");
            ndList.add(str);
            ndList.add(nd.getUserId());
            String ndStr = StringUtils.join(ndList, ",");
            nldList.add(ndStr);
        }

        return StringUtils.join(nldList, ";");
    }

    //获取康复训练
    public static List<NursinglogDetailVo> getRecoveryList(String info){
        //服务集合
        List<NursinglogDetailVo> infoList = new ArrayList<NursinglogDetailVo>();
        //获取服务数组
        String infos[] =info.split(";");
        for(int i=0;i<=infos.length-1;i++){
            //服务
            NursinglogDetailVo nlogDetail = new NursinglogDetailVo();
            String str[] = infos[i].split(",");

            //定义老人id集合
            List<Integer> oldManList = new ArrayList<Integer>();
            //定义老人姓名集合
            List<String> oldmanNameList = Lists.newArrayList();
            if(!infos[i].equals("0,0")){
                //第二个存放负责人id
//                nlogDetail.setUserId(str[1]);
                /*
                 * 2019-11-21
                 * 结构修改为:
                 * oldmans[k] : 护工id:护工姓名
                 * */
                String[] userIdAndName = str[1].split(":");
                nlogDetail.setUserId(userIdAndName[0]);
                nlogDetail.setUserName(userIdAndName[1]);

                //第一个存放老人id集合，以逗号分开
                String oldMans[] = str[0].split("-");
                for(int k = 0,j=oldMans.length-1;k<=j;k++){
                    if (!oldMans[k].equals("0")) {
                        /*
                         * 2019-11-21
                         * 结构修改为:
                         * oldmans[k] : 老人id:老人姓名
                         * */
    //                    oldmanList.add(Integer.valueOf(oldMans[k]));
                        String[] oldmansIdAndName = oldMans[k].split(":");
                        oldManList.add(Integer.parseInt(oldmansIdAndName[0]));
                        oldmanNameList.add(oldmansIdAndName[1]);
                    }
                }
            }
            nlogDetail.setOldMans(oldManList);
            nlogDetail.setOldManNameList(oldmanNameList);
            infoList.add(nlogDetail);
        }
        return infoList;
    }

    //获取食物名称集合
    public static List<String> getFoodNameList(String info){
        //食物名称集合
        List<String> foodName = new ArrayList<String>();
        //获取食物名称数组
        String foods[] =info.split("-");
        for(int i=0;i<=foods.length-1;i++){
            foodName.add(foods[i]);
        }
        return foodName;
    }
    //获取护工id集合
    public static List<Long> getUserList(String info){
        //食物名称集合
        List<Long> userIdList = new ArrayList<Long>();
        //获取食物名称数组
        String users[] =info.split("-");
        for(int i=0;i<=users.length-1;i++){
            userIdList.add(Long.valueOf(users[i]));
        }
        return userIdList;
    }
}
